<?php
/***********************************************************************
 * @package     IvanEngine
 * @subpackage  Framework
 * @author      Ivan <ivanzx@msn.com>
 * @created     2010-07-21
 ***********************************************************************/
if(defined("IVANENGINE_FRAMEWORK_HELPER"))
    die("Redefinition macro in :".__FILE__."(".__LINE__.")");
define("IVANENGINE_FRAMEWORK_HELPER", true);

require_once (dirname(__FILE__).'/../Common.php');

function _AjaxOption($options){
    $options = array_merge($options, array('ajax' => 'get', 'function' => 
        'function(responseText, textStatus){'.'AjaxProcess(responseText, \'body\');}'));
    unset($options['window']);
    return $options;
}

function AjaxTo($url, $options = array())
{
    return HUrl::AjaxTo($url, _AjaxOption($options));
}

function UrlFor($url, $absolute = false)
{
    return HUrl::UrlFor($url, $absolute);
}

function LinkTo($url, $name = '', $options = array())
{
    return HUrl::LinkTo($url, $name, _AjaxOption($options));
}

function LinkToIf($condition, $uri, $name = '', $options = array())
{
    return HUrl::LinkToIf($condition, $uri, $name, _AjaxOption($options));
}

function LinkToUnless($condition, $uri, $name = '', $options = array())
{
    return HUrl::LinkToUnless($condition, $uri, $name, _AjaxOption($options));
}

function ButtonTo($uri, $name = '', $options = array())
{
    return HUrl::ButtonTo($uri, $name, _AjaxOption($options));
}

function MailTo($email, $name = '', $options = array(), $default_value = array())
{
    return HUrl::MailTo($email, $name , $options, $default_value);
}

function IncludeJS($path)
{
    $fileContent = HFile::Read($path, false);
    if( $fileContent === FALSE ){
        throw new CExceptionInvalidArgument("Include js file failed. can not find the file: ".$path);
    }
    if( !empty($fileContent) ){
        echo '<script type="text/javascript">'.M_DS.$fileContent.M_DS.'</script>';        
    }
    //echo '<script type="text/javascript" src="'.HUrl::CorrectUrl($path).'"></script>'."\n";
}

function IncludeCSS($path)
{
    $fileContent = HFile::Read($path, false);
    if( $jsCode === FALSE ){
        throw new CExceptionInvalidArgument("Include css file failed. can not find the file: ".$path);
    }
    if( !empty($fileContent) ){
        echo '<style>'.M_DS.$fileContent.M_DS.'</style>';        
    }
}

function OutputToWindow_Begin($windowName, $renderMode = CView::RM_APPEND)
{
    echo '<!--#W#'.CWindow::ID($windowName).'||'.$renderMode.'#W#-->';
}

function OutputToWindow_End($windowName, $renderMode = CView::RM_APPEND)
{
    OutputToWindow_Begin($windowName, $renderMode);
}
?>
